package com.zxy;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("张三");
        list.add("张三");
        list.add("张三");
        list.add("张三");
        System.out.println(list);

        ArrayList<String> newList = new ArrayList<>((new HashSet<>()));


//1.创建HashSet对象

        HashSet<String> hashSet = new HashSet<>();
//2.保存数据
       hashSet.add("张淇");
        hashSet.add("张淇");
        hashSet.add("张淇");
        hashSet.add("杨斯淇");
        hashSet.add("郑巧");
        System.out.println(hashSet);
        //3.取数据（迭代器）
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }

        for (int i = 0; i < list.size(); i++) {


        }//用不了这个for循环

        //4.取数据（增强for循环）
        for (String name : hashSet) {
            System.out.println("name="+name);
        }
        int[] arr={1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            System.out.println(i);
        }
        //5.取数据（Lambda）
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("----------------");


        //lambda表达式的表达形式
        hashSet.forEach(s -> System.out.println(s));
        System.out.println("----------------");


        //lambda表达式替换成方法引用
        hashSet.forEach(System.out::println);
        System.out.println("----------------");

        Student student = new Student("张三",56);
        //toString方法
        System.out.println(student.toString());
    }
}